package bit_exercises.Day7;

/**
 * @author zerorain
 * @date 2022/04/24 23:48
 **/
//第一题 fibonacii数列
//import java.util.*;
//public class Main{
//    public static void main(String[] args){
//        Scanner sc = new Scanner(System.in);
//        long n = sc.nextLong();
//        long[] arr = new long[(int) (n+8)];
//        arr[0] = 0;
//        arr[1] = 1;
//        long ret = 0;
//        for(long i = 2; i < n+8 ; i++){
//            arr[(int) i] = arr[(int) (i-1)] + arr[(int) (i-2)];
//            if (arr[(int) i - 1] < n && n < arr[(int) (i)]){
//                long a = n - arr[(int) i-1];
//                long b = arr[(int) (i)] - n;
//                if(a < b){
//                    ret = a;
//                    break;
//                }
//                if (a > b){
//                    ret = b;
//                    break;
//                }
//            }
//        }
//        System.out.println(ret);
//
//    }
//}
//  第二题 合法括号序列判断
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long[] arr = new long[(int) (n+8)];
        arr[0] = 0;
        arr[1] = 1;
        long ret = 0;
        for(long i = 2; i < n+8 ; i++){
            arr[(int) i] = arr[(int) (i-1)] + arr[(int) (i-2)];
            if (arr[(int) i - 1] < n && n < arr[(int) (i)]){
                long a = n - arr[(int) i-1];
                long b = arr[(int) (i)] - n;
                if(a < b){
                    ret = a;
                    break;
                }
                if (a > b){
                    ret = b;
                    break;
                }
            }
        }
        System.out.println(ret);

    }
}